import http from '../../util/http';
import * as api from '../../util/api';
const state ={
    GoodsDadaA:[],
    GoodsDada1A:[],
    currentDataA:0,
};

const actions={
    DataA({commit},num){  //查询收藏商品列表
        if(num===undefined){
            num=1;
        }
        num=num++
        let clientId=sessionStorage.getItem('clientId')
        return http({
            url:api.DataA,
            method:'post',
            data:{
                 clientId:"7bff3ee541e746f786623dfc7bb39cfb",
                 condition:{
                 currentPage:num,perSize:5
                }
            }
        }).then(res=>{
            commit('getGoodsA',res.data.data.goodsList)
            commit('getCountA',res.data.data.totalCount)
            return res.data.data //将数据返回给页面，处理异步
        }).catch(err=>{
            console.log(err)
        })
    },
    Data1A({commit},num){  //查询收藏商品列表 图片
        if(num===undefined){
            num=1;
        }
        num=num++
        // console.log(num)
        return http({
            url:api.Data1A,
            method:'post',
            data:{
                clientId:"7bff3ee541e746f786623dfc7bb39cfb",
                condition:{
                    currentPage:num,perSize:8
                }
            }
        }).then(res=>{
            commit('getGoodsB',res.data.data.goodsList)
            commit('getCountA',res.data.data.totalCount)
            return res.data.data //将数据返回给页面，处理异步
        }).catch(err=>{
            console.log(err)
        })
    },
    queryCollectionByKeyword({commit},command){          //收藏商品排序
        if(command===undefined){
            command=0;
        }
        command=command++
        // console.log(command)
        return http({
            url:api.queryCollectionByKeyword,
            method:'post',
            data:{
                currentPage:1,
                perSize:5,
                selectValue:command,
                inputValue:0,
            }
        }).then(res=>{
            commit('selectGoods',res.data)
            console.log(res.data.data)
            return res.data.data //将数据返回给页面，处理异步
        })
    },
}


const mutations={
    getGoodsA(state,obj){
        state.GoodsDadaA = obj
    },
    getGoodsB(state,obj){
        state.GoodsDada1A = obj
    },
    getCountA(state,obj){    //分页
        state.currentDataA = obj
    },
    selectGoods(state,obj){      //排序
        state.GoodsDadaA = obj
    },
}

export default {
    state,
    actions,
    mutations
}